<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";

$conn = new mysqli($servername, $username, $password, $dbname);
$conn->set_charset("utf8mb4");
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}

$sql = "SELECT name, src, intro, moreinfo FROM encyclopedia_department";
$result = $conn->query($sql);

$data = [];
$total = 0;

if ($result->num_rows > 0) {
    $total = $result->num_rows;
    while ($row = $result->fetch_assoc()) {
        $data[] = $row;
    }
}

$conn->close();

$response = [
    'total' => $total,
    'data' => $data
];

header('Content-Type: application/json');
echo json_encode($response, JSON_UNESCAPED_UNICODE);
?>
    